package com.xbongbong.saas.service;

import com.alibaba.fastjson.JSONArray;
import com.xbongbong.paas.domain.entity.ext.PaasFormDataEntityExt;
import com.xbongbong.paas.pojo.FieldAttrEntityForImport;
import com.xbongbong.paas.pojo.dto.FormDataAddDTO;
import com.xbongbong.paas.pojo.dto.FormDataListDTO;
import com.xbongbong.paas.pojo.dto.ImportFormDataDTO;
import com.xbongbong.paas.pojo.dto.SaasFormSaveDTO;
import com.xbongbong.paas.pojo.dto.ValidateDataDTO;
import com.xbongbong.paas.pojo.imports.CellTitlePojo;
import com.xbongbong.paas.pojo.imports.RowGroupPojo;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.pro.applist.pojo.vo.ListAppVO;
import com.xbongbong.pro.businessdata.pojo.dto.FormatExplainDTO;
import com.xbongbong.pro.formexplain.pojo.dto.HandlerExplainBatchLinkItemDTO;
import com.xbongbong.pro.formexplain.pojo.dto.HandlerExplainInLinkItemDTO;
import com.xbongbong.pro.invoice.pojo.InvoiceCommonSavePojo;
import com.xbongbong.pro.invoice.pojo.dto.InvoiceDeleteBatchDTO;
import com.xbongbong.pro.invoice.pojo.dto.InvoiceGetByPurchaseIdDTO;
import com.xbongbong.pro.invoice.pojo.vo.InvoiceDeleteBatchVO;
import com.xbongbong.pro.invoice.pojo.vo.InvoiceGetByPurchaseIdVO;
import com.xbongbong.pro.listbatch.pojo.dto.AddLabelDTO;
import com.xbongbong.pro.purchaseinvoice.dto.PurchaseInvoiceAmountDetailGetDTO;
import com.xbongbong.pro.purchaseinvoice.dto.PurchaseInvoiceEditAttrUpdateDTO;
import com.xbongbong.pro.purchaseinvoice.pojo.PurchaseInvoiceCancelOrRestorePojo;
import com.xbongbong.pro.purchaseinvoice.vo.PurchaseInvoiceAmountDetailVO;
import com.xbongbong.saas.enums.XbbRefTypeEnum;

import java.util.Collection;
import java.util.List;
import java.util.Map;

public interface PurchaseInvoiceService{
    /**
     * 发票保存前saas特殊校验
     *
     * @param validateDataDTO saas特殊校验数据入参
     * @throws XbbException 业务异常
     * @author feng.zheng
     * @date 2019/1/18
     */
    void beforeSave(ValidateDataDTO validateDataDTO) throws XbbException;

    /**
     * 发票保存后逻辑
     *
     * @param saasFormSaveDTO saas保存数据
     * @throws XbbException 业务异常
     * @author feng.zheng
     */
    void afterSave(SaasFormSaveDTO saasFormSaveDTO) throws XbbException;

    /**
     * 批量删除
     * @param invoiceDeleteBatchDTO
     * @return
     * @throws XbbException
     */
    InvoiceDeleteBatchVO deleteBatch(InvoiceDeleteBatchDTO invoiceDeleteBatchDTO) throws XbbException;



    /**
     * Description: 一致性同步
     * @param corpid
     * @param supplierId
     * @param supplierName
     * @return void
     * @author yuqian
     * @date 2020/3/30 15:12
     * @since v1.0
     */
    void dataConsistencyUpdateSupplier(String corpid, Long supplierId, String supplierName) throws XbbException;

    /**
     * 回滚
     * @param idIn
     * @param corpid
     * @throws XbbException
     */
    void updateRollback(List<Long> idIn, String corpid) throws XbbException;



    /**
     * 新建时格式化解释
     *
     * @param formatExplainDTO 入参
     * @throws XbbException 异常
     */
    void formatAddExplain(FormatExplainDTO formatExplainDTO) throws XbbException;

    /**
     * 将Excel数据格式化成表单保存需要的JSON格式的数据
     *
     * @param importFormDataDTO 导入入参
     * @param titlePojoList     标题
     * @param rowGroupPojo      一个表单对应的一组Excel填写的数据
     * @param fieldAttrList     解释
     * @return FormDataAddDTO
     * @throws XbbException XbbException
     * @author feng.zheng
     * @date 2019/5/20 14:16
     * @since V1.0
     */
    FormDataAddDTO formatExcelValue(ImportFormDataDTO importFormDataDTO, List<CellTitlePojo> titlePojoList, RowGroupPojo rowGroupPojo, List<FieldAttrEntityForImport> fieldAttrList) throws XbbException;

    /**
     * 格式化导出值
     *
     * @param paasFormDataESList 数据
     * @throws XbbException 异常
     */
    void formatExportValue(List<PaasFormDataEntityExt> paasFormDataESList, FormDataListDTO formDataListDTO, List<FieldAttrEntityForImport> fieldAttrList);


    /**
     * 发票作废还原删除都可用此接口更新其他业务发票金额
     *
     * @param corpid 公司id
     * @param purchaseInvoiceCancelOrRestorePojo 发票作废或还原的pojo
     * @param isCancel 作废，还原为0
     * @param isDelete 删除为1
     * @param businessType 业务类型
     * @throws XbbException 异常
     */
    void updateInvoiceMoney(String corpid, PurchaseInvoiceCancelOrRestorePojo purchaseInvoiceCancelOrRestorePojo, Integer isCancel, Integer isDelete, Integer businessType) throws XbbException;
    /**
     * 获取relationMap来判断金额
     *
     * @param isHasPaymentSheet 是否有回款单
     * @param corpid       公司id
     * @param purchaseIds  合同集合
     * @param refIds   回款集合
     * @return relationMap
     * @author feng.zheng
     * @date 2019/2/27 11:10
     */
    Map<String, Object> getRelationMapForJudgeMoney(boolean isHasPaymentSheet, boolean isPrePaySheet,boolean isPrePaySheetUnion,boolean isHasPayment, String corpid, List<Long> purchaseIds, List<Long> refIds) throws XbbException;

    /**
     * 批量获取红冲总金额
     *
     * @param originIdIn 原始id
     * @param negIdIn 排除发票id
     * @param corpid 公司id
     * @return double
     * @throws XbbException 异常
     */
    Map<Long, Double> getRedTotalMoneyByIdIn(List<Long> originIdIn,List<Long> negIdIn, String corpid) throws XbbException;
    /**
     * 合并开票
     *
     * @param corpid  公司id
     * @param purchaseInvoiceId  发票id
     * @param invoiceMoney 开票金额
     * @param relationIdIn 传参
     * @param isImport 是否导入
     * @param amountDetail 金额明细
     * @author feng.zheng
     * @throws XbbException 异常
     * @date 2019/2/26 18:44
     */
    void invoiceAmountJudgment(String corpid, Long purchaseInvoiceId, Double invoiceMoney, Map<String, Object> relationIdIn, Integer isImport, Integer isCover, Integer isRestore, JSONArray amountDetail) throws XbbException;


    /**
     * 关联新建时格式化解释
     *
     * @param handlerExplainInLinkItemDTO 入参
     * @throws XbbException 异常
     * @author feng.zheng
     * @date 2019-03-16 20:53
     */
    void formatLinkAddExplain(HandlerExplainInLinkItemDTO handlerExplainInLinkItemDTO) throws XbbException;


    /**
     * 批量编辑某个字段
     * @author 余乾
     * @date 2020/4/27 15:35
     * @param purchaseInvoiceEditAttrUpdateDTO
     * @return void
     * @throws XbbException 业务异常
     */
    void batchEditAttr(PurchaseInvoiceEditAttrUpdateDTO purchaseInvoiceEditAttrUpdateDTO) throws XbbException;
    /**
     * 合并开票
     *
     * @param handlerExplainBatchLinkItemDTO 入参
     * @throws XbbException 异常
     */
    void formatBatchLinkAddExplain(HandlerExplainBatchLinkItemDTO handlerExplainBatchLinkItemDTO) throws XbbException;

    /**
         * 格式化移动端列表页
         *
         * @param formDataListDTO 用户
         * @param esEntities 业务实体集合
         * @param totalCount 总数
         * @return ListAppVO
         * @throws XbbException
         * @author yuqian
         * @date 2019-03-11 13:50
         */
    ListAppVO formatInvoiceAppList(FormDataListDTO formDataListDTO, List<PaasFormDataEntityExt> esEntities, Integer totalCount) throws XbbException;
    
    void checkBusinessDeleteHaveInvoice(List<Long> idList, String corpid, XbbRefTypeEnum xbbRefTypeEnum, Collection<String> errorTypeSet, Collection<String> errorDataSet, Collection<Long> delIdList, Collection<String> delNoList,Map<String,Long> parentMap,Map<Long,String> parentSerialNoMap,Map<Long,String> subMap,Map<String,List<Long>> uuidSubMap,Map<String,List<String>> uuidSerialNoMap) throws XbbException;

    /**
     * 获取进项发票金额明细
     * @param purchaseInvoiceAmountDetailGetDTO
     * @return
     */
    PurchaseInvoiceAmountDetailVO getPurchaseInvoiceAmountDetail(PurchaseInvoiceAmountDetailGetDTO purchaseInvoiceAmountDetailGetDTO) throws XbbException;

    /**
     * 根据采购合同ID获取发票列表
     * @param invoiceGetByPurchaseIdDTO 入参
     * @return 发票信息
     * @throws XbbException error
     * @author zhouwq
     * @date 2020/3/18 14:40
     */
    InvoiceGetByPurchaseIdVO getByPurchase(InvoiceGetByPurchaseIdDTO invoiceGetByPurchaseIdDTO) throws XbbException;



    /**
     * 进项发票管理供应商 一致性同步
     * @param corpid 公司id
     * @param purchaseId 付款计划id
     * @param serialNo 付款计划编号
     * @throws XbbException
     */
    void dataConsistencyUpdatePurchase(String corpid, Long purchaseId, String serialNo);


    /**
     * 进项发票管理付款计划一致性同步
     * @param corpid　公司ID
     * @param payPlanId 付款计划Id
     * @param serialNo 付款计划 编号
     * @throws XbbException
     * @author yuqian
     * @date 2020-05-11 15:24
     * @since v1.0
     * @version v1.0
     */
    void dataConsistencyUpdatePayPlan(String corpid,Long payPlanId,String serialNo) throws XbbException;

    /**
     *  批量增删标签
     * @param addLabelDTO
     * @param addBatchList
     * @throws XbbException
     */
    void updateBatchLabelAttr(AddLabelDTO addLabelDTO, List<PaasFormDataEntityExt> addBatchList, Boolean addOrDelete) throws XbbException;

    void afterSaveForWorkflow(SaasFormSaveDTO saasFormSaveDTO) throws XbbException;

    void afterSaveForUpdateWorkflow(SaasFormSaveDTO saasFormSaveDTO) throws XbbException;


    void invoiceCommonSaveHandle(InvoiceCommonSavePojo invoiceCommonSavePojo)throws XbbException;
}
